/**
 * Author: Dmitry Ustimov
 * Date: 5/14/13
 * Time: 10:06 PM
 */

package com.gmail.dmitryustimov.ms.java7.mediator.classic.example.classic_example3;

public class Fan {

    FacebookGroupMediator mediator;
    protected String name;
    Receiver receiver;

    public Fan() {
    }

    public Fan(FacebookGroupMediator mediator, String name) {
        this.name = name;
        this.mediator = mediator;
        this.receiver = this.new FanReceiver();
        mediator.signOn(this.receiver);
    }

    public class FanReceiver implements Receiver {
        @Override
        public void receive(String message, String from) {
            System.out.println(name + " received from " + from + ": " + message);
        }
    }

    public void send(String message) {
        System.out.println("Send (From " + name + "): " + message);
        mediator.send(message, name);
    }
}
